文档

API详情

更新时间:
一键部署

本文主要介绍如何使用API调用阿里云百炼的流程编排应用,也就是从应用中心中创建的流程编排应用。

SDK使用

前提条件

快速调用

以下示例展示了调用流程编排应用来调用自定义插件进行实时天气查询问答。

说明

需要使用您的API-KEY替换示例中的YOUR_API_KEY,并将APP-ID替换示例中的YOUR_APP_ID,代码才能正常运行。

python sdk version: dashscope>=1.10.0

java sdk version: >=2.5.0

设置API-KEY

export DASHSCOPE_API_KEY=YOUR_API_KEY

调用示例

from http import HTTPStatus
from dashscope import Application


def flow_call():
    response = Application.call(app_id='YOUR_APP_ID',
                                prompt='杭州的天气怎么样',
                                )

    if response.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
    else:
        print('request_id=%s\n output=%s\n usage=%s\n' % (response.request_id, response.output, response.usage))


if __name__ == '__main__':
    flow_call()
import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import java.util.List;


public class Main{
    public static void flowCall()
            throws ApiException, NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
                .appId("YOUR_APP_ID")
                .prompt("杭州的天气怎么样")
                .topP(0.2)
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());
    }

    public static void main(String[] args) {
        try {
            flowCall();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }  
}

业务参数透传

自定义参数透传通常用在调用流程编排应用时,透传业务参数。比如在以下场景中可能用到业务参数透传:

  • 在流程编排应用中,需要传递流程编排中指定的变量值。

from http import HTTPStatus
from dashscope import Application


def flow_call_with_param():
    # 查询今天的天气
    biz_params = {'date': '今天'}

    response = Application.call(app_id='YOUR_APP_ID',
                                prompt='杭州的天气怎么样',
                                top_p=0.2,
                                biz_params=biz_params,  # 传递业务参数
                                has_thoughts=True,      # 开启插件调用过程返回结果
                                )

    if response.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
    else:
        print('request_id=%s\n output=%s\n usage=%s\n' % (response.request_id, response.output, response.usage))

        thoughts = response.output.thoughts
        if thoughts is not None:
            for thought in thoughts:
                print('thought=%s' % thought)


if __name__ == '__main__':
    flow_call_with_param()
import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.utils.JsonUtils;
import java.util.Arrays;

public class Main {
    public static void flowCallWithParam()
            throws ApiException, NoApiKeyException, InputRequiredException {

        //查询今天的天气
        String bizParams = "{\"date\": \"今天\"}";

        ApplicationParam param = ApplicationParam.builder()
                .appId(APP_ID)
                .prompt("杭州的天气怎么样")
                // 传递业务参数
                .bizParams(JsonUtils.parse(bizParams))
                // 开启插件调用过程返回结果
                .hasThoughts(true)
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());

        List<ApplicationOutput.Thought> thoughts = result.getOutput().getThoughts();
        if (thoughts != null && thoughts.size() > 0) {
            for (ApplicationOutput.Thought thought : thoughts) {
                System.out.printf("thought: %s\n", thought);
            }
        }
    }

      public static void main(String[] args) {
        try {
        		flowCallWithParam();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }
}

多轮会话

云端托管多轮会话

阿里云百炼应用提供云端托管多轮对话功能,通过session_id进行多轮会话,阿里云百炼云端将自动托管多轮会话,调用侧无需自行维护多轮会话。

下面的例子中,第一次调用后返回session_id,在第二次调用时,可以传入第一次返回的session_id,那么第二次调用模型服务时,将携带第一次调用的会话信息。

说明

目前session id会话有效期是1个小时,最大历史会话轮数为50。

如果同时传入session id和history时,优先使用传入的history,不再使用托管的多轮会话。

from http import HTTPStatus
from dashscope import Application


def call_with_session():
    response = Application.call(app_id='YOUR_APP_ID',
                                prompt='我想去新疆',
                                )

    if response.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
        return

    response = Application.call(app_id='your app id',
                                prompt='那边有什么旅游景点或者美食?',
                                top_p=0.2,
                                session_id=response.output.session_id
                                )
    if response.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
    else:
        print('request_id=%s, output=%s, usage=%s\n' % (response.request_id, response.output, response.usage))


if __name__ == '__main__':
    call_with_session()
import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;

import java.util.Arrays;
import java.util.List;

public class Main {
      public static void callWithSession()
            throws ApiException, NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
                .appId("YOUR_APP_ID")
                .prompt("我想去新疆")
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        param.setSessionId(result.getOutput().getSessionId());
        param.setPrompt("那边有什么旅游景点或者美食?");
        result = application.call(param);

        System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());
    }
  
   public static void main(String[] args) {
        try {
						callWithSession();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }  
}

调用侧传入多轮会话

调用侧自行维护多轮会话时,可以通过history传入多轮会话信息。

from http import HTTPStatus
from dashscope import Application


def call_with_history():
    prompt = '我想去新疆'
    response = Application.call(app_id="YOUR_APP_ID",
                                prompt=prompt,
                                )

    if response.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
        return

    history = [{'user': prompt, 'bot': response.output.text}]
    response = Application.call(app_id="YOUR_APP_ID",
                                prompt='那边有什么旅游景点或者美食?',
                                history=history
                                )
    if response.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
    else:
        print('request_id=%s, output=%s, usage=%s\n' % (response.request_id, response.output, response.usage))


if __name__ == '__main__':
    call_with_history()
import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.common.History;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;

import java.util.Arrays;
import java.util.List;

public class Main {
    public static void callWithHistory()
            throws ApiException, NoApiKeyException, InputRequiredException {
        String prompt = "我想去新疆";
        ApplicationParam param = ApplicationParam.builder()
                .appId(APP_ID)
                .prompt("我想去新疆")
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        param.setHistory(Arrays.asList(History.builder()
                .user(prompt)
                .bot(result.getOutput().getText())
                .build()));
        param.setPrompt("那边有什么旅游景点或者美食?");
        result = application.call(param);

        System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());
    }

  
   public static void main(String[] args) {
        try {
						callWithHistory();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }  
}

流式输出

流式输出需要添加对应参数。其中,Python SDK中需要添加stream=True,Java SDK中需要使用streamCall接口调用。

from http import HTTPStatus
from dashscope import Application


def call_with_stream():
    responses = Application.call(app_id='YOUR_APP_ID',
                                 prompt='如何做炒西红柿鸡蛋?',
                                 stream=True
                                 )

    for response in responses:
        if response.status_code != HTTPStatus.OK:
            print('request_id=%s, code=%s, message=%s\n' % (
                response.request_id, response.status_code, response.message))
        else:
            print('output=%s, usage=%s\n' % (response.output, response.usage))


if __name__ == '__main__':
    call_with_stream()
import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import io.reactivex.Flowable;

import java.util.Arrays;
import java.util.List;

public class Main {
      public static void streamCall() throws NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
                .appId("YOUR_APP_ID")
                .prompt("如何做炒西红柿鸡蛋?")
                .build();

        Application application = new Application();
        Flowable<ApplicationResult> result = application.streamCall(param);
        result.blockingForEach(data -> {
            System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                    data.getRequestId(), data.getOutput().getText(), data.getOutput().getFinishReason());

        });
    }

    public static void main(String[] args) {
        try {
		        streamCall();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }
}

业务空间

上述调用示例调用的是默认业务空间的应用,如果需要调用其他业务空间,需要传入指定的业务空间标识。

说明

请将WORKSPACE替换示例中的YOUR_WORKSPACE,代码才能正常运行。请参考Workspace ID获取WORKSPACE。

from http import HTTPStatus
from dashscope import Application


def call_with_workspace():
    response = Application.call(app_id='YOUR_APP_ID',
                                workspace='YOUR_WORKSPACE',
                                prompt='如何做炒西红柿鸡蛋?',
                                top_p=0.2,
                                )

    if response.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
    else:
        print('request_id=%s, text=%s, usage=%s\n' % (response.request_id, response.output.text, response.usage))


if __name__ == '__main__':
    call_with_workspace()
import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;

public class Main {
      public static void callWithWorkspace() throws NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
                .workspace("YOUR_WORKSPACE")
                .appId("YOUR_APP_ID")
                .prompt("如何做炒西红柿鸡蛋?")
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());
    }

    public static void main(String[] args) {
        try {
		        callWithWorkspace();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }
}

输入参数

参数

类型

默认值

说明

app_id

string

-

应用标识。

prompt

string

-

用户当前输入的期望模型执行指令,用于指导模型生成回复。

session_id

string

-

对话历史会话唯一标识,传入session_id后,将在云端进行对话历史进行记录,调用大模型将自动携带存储的对话历史。请确保session_id不重复,并且session_id和history二选一即可。

history (可选)

list[dict]

[]

用户与模型的对话历史,list中的每个元素是形式为{"user":"用户输入","bot":"模型输出"}的一轮对话,多轮对话按时间顺序排列。

workspace(可选)

string

-

业务空间标识。

seed (可选)

int

1234

生成时使用的随机数种子,用户控制模型生成内容的随机性。seed支持无符号64位整数,默认值为1234。在使用seed时,模型将尽可能生成相同或相似的结果,但目前不保证每次生成的结果完全相同。

top_p (可选)

float

0.2

生成过程中核采样方法概率阈值,例如,取值为0.2时,仅保留概率加起来大于等于0.2的最可能token的最小集合作为候选集。取值范围为(0,1.0),取值越大,生成的随机性越高;取值越低,生成的确定性越高。

top_k (可选)

int

None

生成时,采样候选集的大小。例如,取值为50时,仅将单次生成中得分最高的50个token组成随机采样的候选集。取值越大,生成的随机性越高;取值越小,生成的确定性越高。默认不传递该参数,取值为None或当top_k大于100时,表示不启用top_k策略,此时,仅有top_p策略生效。

temperature (可选)

float

1.0

用于控制随机性和多样性的程度。具体来说,temperature值控制了生成文本时对每个候选词的概率分布进行平滑的程度。较高的temperature值会降低概率分布的峰值,使得更多的低概率词被选择,生成结果更加多样化;而较低的temperature值则会增强概率分布的峰值,使得高概率词更容易被选择,生成结果更加确定。

取值范围: [0, 2),不建议取值为0,无意义。

python version >=1.10.1

java version >= 2.5.1

stream (可选)

bool

False

是否使用流式输出。当以stream模式输出结果时,接口返回结果为generator,需要通过迭代获取结果,默认每次输出为当前生成的整个序列,最后一次输出为最终全部生成结果,可以通过参数incremental_output为False改变输出模式为非增量输出。

biz_params(可选)

dict

-

业务API使用的参数,可以直接进行透传。当调用侧在调用流程编排应用时,需要将业务参数传递给业务方的API时,可以使用此参数,比如userId、token等。

has_thoughts

bool

False

是否输出检索召回处理过程信息。开启后,将返回文档检索召回和模型推理的过程信息。

输出参数

返回参数

类型

说明

备注

status_code

int

200(HTTPStatus.OK)表示请求成功,否则表示请求失败,可以通过code获取错误码,通过message字段获取错误详细信息。

说明

Python才有这个字段,Java失败会抛异常,异常信息为code,message内容。

request_Id

string

系统生成的标志本次调用的id。

code

string

表示请求失败,表示错误码,成功忽略。

python only

message

string

失败,表示失败详细信息,成功忽略。

python only

output

dict

调用结果信息,对于千问模型,包含输出text。

usage

dict

计量信息,表示本次请求的计量数据。

output.text

string

模型生成回复。

output.finish_reason

string

正在生成时为null,生成结束时如果由于停止token导致则为stop。

output.session_id

string

对话历史会话的唯一标识.

在多轮会话时,可以使用此标识进行多轮会话保持。

usage.models[].model_id

string

本次应用调用到的模型。

usage.models[].input_tokens

int

用户输入文本转换成Token后的长度。

usage.models[].output_tokens

int

模型生成回复转换为Token后的长度。

output.thoughts[].throught

string

模型的思考结果。

output.thoughts[].action_type

string

大模型返回的执行步骤类型

api: 执行api插件, response: 返回最终结果。

output.thoughts[].action_name

string

执行的action名称,如文档检索、API插件。

output.thoughts[].action

string

执行的步骤。

output.thoughts[].action_input_stream

string

入参的流式结果。

output.thoughts[].action_input

string

插件的输入参数。

output.thoughts[].response

string

模型调用返回的结果。

output.thoughts[].observation

string

检索或插件的返回结果。

HTTP调用接口

功能描述

应用调用同时支持 HTTP 调用来完成客户的响应,目前提供普通 HTTP 和 HTTP SSE 两种协议,您可根据自己的需求自行选择。

前提条件

提交接口调用

POST https://dashscope.aliyuncs.com/api/v1/apps/{YOUR_APP_ID}/completion

入参描述

传参方式

字段

类型

必选

描述

示例值

Header

Content-Type

String

请求类型:application/json

application/json

Accept

String

*/*,选择text/event-stream则会开启 SSE 响应,默认无设置

text/event-stream

Authorization

String

API-Key,例如:Bearer d1**2a

Bearer d1**2a

X-DashScope-SSE

String

跟Accept: text/event-stream 二选一即可启用SSE响应

enable

X-DashScope-WorkSpace

String

业务空间标识。

ws_ik******RVYCKzt

Body

input.prompt

String

用户当前输入的期望模型执行指令,支持中英文。

哪个公园距离我更近

input.history

List

用户与模型的对话历史,list中的每个元素是形式为{"user":"用户输入","bot":"模型输出"}的一轮对话,多轮对话按时间正序排列。

"history": [

{

"user":"今天天气好吗?",

"bot":"今天天气不错,要出去玩玩嘛?"

},

{

"user":"那你有什么地方推荐?",

"bot":"我建议你去公园,春天来了,花朵开了,很美丽。"

}

]

input.session_id

String

对话历史会话唯一标识, 传入session_id后,将在云端进行对话历史进行记录,调用大模型将自动携带存储的对话历史。请确保session_id不重复,并且session_id和history二选一即可。

input.biz_params

JSON

业务API使用的参数,可以直接进行透传。当调用侧在调用流程编排应用时,需要将业务参数传递给业务方的API时,可以使用此参数,比如userId、token等。

{"userId": "123"}

parameters.seed

Integer

生成时使用的随机数种子,用户控制模型生成内容的随机性。seed支持无符号64位整数,默认值为1234。在使用seed时,模型将尽可能生成相同或相似的结果,但目前不保证每次生成的结果完全相同。

65535

parameters.top_p

Float

生成时,核采样方法的概率阈值。例如,取值为0.2时,仅保留累计概率之和大于等于0.2的概率分布中的token,作为随机采样的候选集。取值范围为(0,1.0),取值越大,生成的随机性越高;取值越低,生成的随机性越低。默认值为0.2。注意,取值不要大于等于1

0.2

parameters.top_k

Integer

生成时,采样候选集的大小。例如,取值为50时,仅将单次生成中得分最高的50个token组成随机采样的候选集。取值越大,生成的随机性越高;取值越小,生成的确定性越高。注意:如果top_k参数为空或者top_k的值大于100,表示不启用top_k策略,此时仅有top_p策略生效,默认是空。

50

parameters.temperature

Float

用于控制随机性和多样性的程度。具体来说,temperature值控制了生成文本时对每个候选词的概率分布进行平滑的程度。较高的temperature值会降低概率分布的峰值,使得更多的低概率词被选择,生成结果更加多样化;而较低的temperature值则会增强概率分布的峰值,使得高概率词更容易被选择,生成结果更加确定。

取值范围:[0, 2),系统默认值为1.0。不建议将值为0,因为这没有意义。

1.0

parameters.has_thoughts

Bool

是否输出检索召回处理过程信息。开启后,将返回文档检索召回和模型推理的过程信息。

出参描述

字段

类型

描述

示例值

status_code

int

200(HTTPStatus.OK)表示请求成功,否则表示请求失败,可以通过code获取错误码,通过message字段获取错误详细信息。

说明

Python才有这个字段,Java失败会抛异常,异常信息为code,message内容。

200

request_Id

string

系统生成的标志本次调用的id。

33dcf25a-******-8b711f15614e

code

string

表示请求失败,表示错误码,成功忽略。

message

string

失败,表示失败详细信息,成功忽略。

output.text

string

模型生成回复。

output.finish_reason

string

正在生成时为null,生成结束时如果由于停止token导致则为stop。

output.session_id

string

对话历史会话的唯一标识.

在多轮会话时,可以使用此标识进行多轮会话保持。

usage.models[].model_id

string

本次应用调用到的模型。

usage.models[].input_tokens

int

用户输入文本转换成Token后的长度。

usage.models[].output_tokens

int

模型生成回复转换为Token后的长度。

output.thoughts[].throught

string

模型的思考结果。

output.thoughts[].action_type

string

大模型返回的执行步骤类型

api: 执行api插件, response: 返回最终结果。

output.thoughts[].action_name

string

执行的action名称,如文档检索、API插件。

output.thoughts[].action

string

执行的步骤。

output.thoughts[].action_input_stream

string

入参的流式结果。

output.thoughts[].action_input

string

插件的输入参数。

output.thoughts[].response

string

模型调用返回的结果。

output.thoughts[].observation

string

检索或插件的返回结果。

请求示例(SSE 关闭)

以下示例展示通过CURL命令来调用流程编排应用的脚本(SSE 关闭)。

说明

需要使用您的API-KEY替换示例中的YOUR_API_KEY,并将APP-ID替换示例中的YOUR_APP_ID,代码才能正常运行。

curl --location 'https://dashscope.aliyuncs.com/api/v1/apps/{YOUR_APP_ID}/completion' \
--header 'Authorization: Bearer {YOUR_API_KEY}' \
--header 'Content-Type: application/json' \
--data '{
    "input": {
        "prompt": "杭州的天气怎么样",
        "biz_params": {"date": "今天"}
    },
    "parameters":  {},
    "debug": {}
}' --verbose

响应示例(SSE关闭)

{
  "output": {
    "finish_reason": "stop",
    "session_id": "06f631b******97afdb3282b",
    "text": " 杭州的天气为小到中雨,气温在15~27℃之间。"
  },
  "usage": {
    "models": [
      {
        "output_tokens": 68,
        "model_id": "qwen-plugin",
        "input_tokens": 459
      },
      {
        "output_tokens": 51,
        "model_id": "qwen-plugin",
        "input_tokens": 583
      }
    ]
  },
  "request_id": "98b95f2b-1453-94ce-a7c7-f7ef3e6ffcfa"
}

请求示例(SSE开启)

以下示例展示通过CURL命令来调用流程编排应用的脚本(SSE 开启)。

说明

需要使用您的API-KEY替换示例中的YOUR_API_KEY,并将APP-ID替换示例中的YOUR_APP_ID,代码才能正常运行。

curl --location 'https://dashscope.aliyuncs.com/api/v1/apps/{YOUR_APP_ID}/completion' \
--header 'Authorization: Bearer {YOUR_API_KEY}' \
--header 'Content-Type: application/json' \
--header 'X-DashScope-SSE: enable' \
--data '{
    "input": {
        "prompt": "杭州的天气怎么样",
        "biz_params": {"date": "今天"}
    },
    "parameters":  {},
    "debug": {}
}' --verbose

响应示例(SSE开启)

id:1
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"0e8f1e9e******9c8c85b088877","finish_reason":"null","text":" 杭州的天气为小到"},"usage":{"models":[{"input_tokens":459,"output_tokens":68,"model_id":"qwen-plugin"},{"input_tokens":583,"output_tokens":38,"model_id":"pre-plugin-888"}]},"request_id":"f936f2f5-52bd-95d4-a739-312649de2e97"}

......
......

id:3
event:result
:HTTP_STATUS/200
data:{"output":{"session_id":"0e8f1e9e4******e9c8c85b088877","finish_reason":"stop","text":" 杭州的天气为小到中雨,气温在15~27℃之间。"},"usage":{"models":[{"input_tokens":459,"output_tokens":68,"model_id":"qwen-plugin"},{"input_tokens":583,"output_tokens":51,"model_id":"pre-plugin-888"}]},"request_id":"f936f2f5-52bd-95d4-a739-312649de2e97"}

请求示例(业务空间)

以下示例展示通过CURL命令来调用指定业务空间的流程编排应用的脚本。

说明

需要使用您的API-KEY替换示例中的YOUR_API_KEY,并将APP-ID替换示例中的YOUR_APP_ID,然后将WORKSPACE替换示例中的YOUR_WORKSPACE,代码才能正常运行。

curl --location 'https://dashscope.aliyuncs.com/api/v1/apps/{YOUR_APP_ID}/completion' \
--header 'Authorization: Bearer {YOUR_API_KEY}' \
--header 'Content-Type: application/json' \
--header 'X-DashScope-WorkSpace: {YOUR_WORKSPACE}' \
--data '{
    "input": {
        "prompt": "如何做土豆炖猪脚?"
    },
    "parameters":  {},
    "debug": {}
}' --verbose

响应示例(业务空间)

{
  "output": {
    "finish_reason": "stop",
    "session_id": "a08c1b4e******0c4513db9eea4",
    "text": "土豆炖猪脚是一道美味可口、营养丰富的家常菜,下面是一种简单的制作方法:\n\n**材料准备:**\n1. 猪脚(猪蹄)500克\n2. 土豆2-3个\n3. 生姜3-4片\n4. 大葱1根\n5. 八角2颗\n6. 桂皮一小块\n7. 香叶2片\n8. 料酒适量\n9. 生抽、老抽各适量\n10. 冰糖适量\n11. 清水适量\n12. 盐适量\n\n**步骤:**\n1. **猪脚处理**:猪脚剁成小块,放入开水中焯水,去除血水和杂质,捞出后用清水冲洗干净备用。\n   \n2. **炒糖色**:锅中加入少量油,放入冰糖小火慢慢熬化至红色且有泡沫时,将焯过水的猪脚块倒入锅中翻煎,使猪脚表面均匀地裹上糖色。\n\n3. **炖煮**:加入切好的姜片、葱段以及八角、桂皮、香叶等香料一同翻炒出香味。然后烹入料酒,加入生抽、老抽调色,再加入足够的热水没过猪脚。\n\n4. **炖煮猪脚**:大火烧沸后撇去浮沫,转中小火慢炖约40分钟至猪脚软烂。\n\n5. **加入土豆**:在猪脚炖至七八成熟时,将土豆削皮切块,加入锅中,继续炖煮约20分钟,直到土豆熟透且能轻易插入筷子。\n\n6. **调味**:最后根据个人口味加盐调味,炖煮几分钟让味道充分融合即可。\n\n7. **出锅**:炖至汤汁浓稠,土豆和猪脚都完全熟透后,撒上葱花或者香菜点缀,即可关火出锅。\n\n以上就是土豆炖猪脚的基本做法,具体炖煮时间可能因猪脚的老嫩程度和个人口感喜好有所不同,可以根据实际情况调整。"
  },
  "usage": {
    "models": [
      {
        "output_tokens": 456,
        "model_id": "qwen-max",
        "input_tokens": 64
      }
    ]
  },
  "request_id": "99432adc-8b15-953f-afba-fd0895a68773"
}

异常响应示例

在访问请求出错的情况下,输出的结果中会通过 code 和 message 指明错误原因。

{"code":"InvalidApiKey","message":"Invalid API-key provided.","request_id":"2637fcf9-32b1-9f4e-b0e9-1724d4aea00e"}

状态码说明

服务调用返回的状态码详情,请参见状态码说明

  • 本页导读 (1)
文档反馈